﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Biz_Dal.Biz;
using System.IO;
using System.Drawing;


namespace Biz_Dal.Biz
{
    public class ImageSach
    {

        /// <summary>
        /// Chuyen  doi gia tri byteArray thanh Image
        /// </summary>
        /// <param name="byteArray">Gia tri dau vao bang byteArray</param>
        /// <returns>Ham tra ve mot bien kieu Image</returns>
        public static Image byteArrayToImage(byte[] byteArray)
        {
            ImageConverter imageConverter = new System.Drawing.ImageConverter();
            Image image = imageConverter.ConvertFrom(byteArray) as Image;
            return image;
        }

        /// <summary>
        /// Chuyen  doi gia tri imageToByteArray
        /// </summary>
        /// <param name="byteArray">Gia tri dau vao Image</param>
        /// <returns>Ham tra ve mot bien kieu byteArray</returns>
        public static byte[] imageToByteArray(Image imageIn)
        {
            MemoryStream ms = new MemoryStream();
            imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            return ms.ToArray();
        }

    }
}
